package cn.crm.web.controller.business;


import cn.crm.common.annotation.Log;
import cn.crm.common.core.controller.BaseController;
import cn.crm.common.core.domain.AjaxResult;
import cn.crm.common.core.page.TableDataInfo;
import cn.crm.common.enums.BusinessType;
import cn.crm.common.utils.poi.ExcelUtil;
import cn.crm.system.domain.pojo.dto.BusinessDto;
import cn.crm.system.domain.pojo.dto.OfferDto;
import cn.crm.system.domain.pojo.vo.BusinessVo;
import cn.crm.system.domain.pojo.vo.CaseVo;
import cn.crm.system.domain.pojo.vo.OfferVo;
import cn.crm.system.domain.pojo.vo.PricePdfVo;
import cn.crm.system.service.IOfferService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/offer")
@Api(tags = "报价管理")
public class OfferController extends BaseController {

    @Autowired
    private IOfferService offerService;

    @GetMapping("/list")
    @ApiOperation("查询报价明细资料")
    @PreAuthorize("@ss.hasPermi('system:offer:list')")
    @Log(title = "报价管理", businessType = BusinessType.OTHER)
    public TableDataInfo GetBusinesslist(OfferDto offerDto) {
        log.debug("开始处理查询客户资料的接口");
        startPage();
        List<OfferVo> offerVos = offerService.selectOfferVoListAndcast(offerDto);
//        return null;
        return getDataTable(offerVos);
    }


    @GetMapping("/offer/{seriesId}")
    @ApiOperation("根据案件公司id查询资料")
    @PreAuthorize("@ss.hasPermi('system:case:query')")
    @Log(title = "案件管理", businessType = BusinessType.OTHER)
    public TableDataInfo getInfoByBusinessId(@PathVariable Long seriesId){
        log.debug("开始通过id查询案件资料的接口");
        startPage();
        List<OfferVo> offerVos = offerService.selectOfferVoListAndcastById(seriesId);
        return  getDataTable(offerVos);
    }


    @Log(title = "报价管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:offer:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, OfferDto offerDto)
    {
        List<OfferVo> offerVos = offerService.selectOfferVoListAndcast(offerDto);
        ExcelUtil<OfferVo> util = new ExcelUtil<OfferVo>(OfferVo.class);
        util.exportExcel(response, offerVos, "报价单数据");
    }


    @Log(title = "报价管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @ApiOperation("删除资料")
    @PreAuthorize("@ss.hasPermi('system:offer:delete')")
    public AjaxResult delete(@PathVariable Long[] id){
        log.debug("开始删除客户资料的接口");
        int deloffer = offerService.deloffer(id);
        if (deloffer < 1){
            return AjaxResult.error("删除报价单失败");
        }

        return AjaxResult.success("删除报价单成功");
    }



    @GetMapping("/listpdf/{id}")
    @ApiOperation("通过id查询pdf")
    @PreAuthorize("@ss.hasPermi('system:offer:selectold')")
    @Log(title = "报价管理", businessType = BusinessType.OTHER)
    public TableDataInfo Getpdflist( @PathVariable Long id) {
        log.debug("开始处理查询pdf的接口");
        List<PricePdfVo> pricePdfVos = offerService.selectpdfListAndcast(id);
//        return null;
        return getDataTable(pricePdfVos);
    }

}
